package cn.itcast.order.service.Impl;

import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import cn.itcast.order.service.OrderService;
import com.Iron.api.UserClient.UserClient;
import com.Iron.api.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl implements OrderService {


    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private OrderMapper orderMapper;

/*    @Autowired
    @Qualifier("curTemplate")
    private RestTemplate restTemplate;*/


    @Autowired
    private UserClient userClient;


    public Order queryOrderById(Long orderId) {

        Order order =  orderMapper.findById(orderId);
        User user = userClient.findById(order.getUserId());
        order.setUser(user);

        return order;
    }
}

   /* public Order queryOrderById(Long orderId) {
        // 通过静态工厂去拿

*//*
        Order order =  orderMapper.findById(orderId);
        String url = "http://localhost:8081/user/" + order.getUserId();;
        order.setUser(BeanFactory.getRestTemplate().getForObject(url, User.class));
*//*

        // 通过原生AutoWired去拿
        Order order =  orderMapper.findById(orderId);
        String url = "http://USERSERVICE/user/" + order.getUserId();
        order.setUser(restTemplate.getForObject(url, User.class));


        return order;
    }*/

/*
@Service
class OrderServiceImpl1 implements OrderService {


    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private OrderMapper orderMapper;

        @Autowired
        @Qualifier("curTemplate")
        private RestTemplate restTemplate;


    public Order queryOrderById(Long orderId) {

        Order order =  orderMapper.findById(orderId);
        String url = "http://USERSERVICE/user/" + order.getUserId();
        order.setUser(restTemplate.getForObject(url, User.class));


        return order;
    }
}
*/
